package com.promise.jokerdream.work.signin.before

import com.promise.jokerdream.database.UserDataManager
import com.promise.jokerdream.manager.ExecutionHistoryManager
import com.promise.jokerdream.repository.GameApi
import com.promise.jokerdream.utils.AppContext
import com.promise.jokerdream.work.BaseWork
import com.promise.jokerdream.work.WorkResult

// 特权卡工作，各种月卡、年卡领取
class PrivilegeCardWork(uin: String): BaseWork(uin) {

    override val name: String
        get() = "特权卡"

    override val priority: Int
        get() = 1

    private val gameApi = GameApi.getInstance()
    private val historyManager by lazy { ExecutionHistoryManager.getInstance(AppContext.get()) }

    override suspend fun executeWork(): WorkResult {
        // 领取斗豆月卡
        val monthlyCardResult = gameApi.getDouDouMonthlyCard(uin)
        monthlyCardResult.fold(
            onSuccess = { response ->
                historyManager.addHistory(name, response.getDescription())
            },
            onFailure = { exception ->
                historyManager.addHistory(name, exception.message)
            }
        )

        return WorkResult.Success
    }
}
